package com.ibm.aglets.tahiti;

/*
 * @(#)SecurityConfigDialog.java
 * 
 * IBM Confidential-Restricted
 * 
 * OCO Source Materials
 * 
 * 03L7246 (c) Copyright IBM Corp. 1996, 1998
 * 
 * The source code for this program is not published or otherwise
 * divested of its trade secrets, irrespective of what has been
 * deposited with the U.S. Copyright Office.
 */

import java.awt.Button;
import java.awt.Checkbox;
import java.awt.Dialog;
import java.awt.Event;
import java.awt.Font;
import java.awt.Choice;
import java.awt.Frame;
import java.awt.CardLayout;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.Label;
import java.awt.List;
import java.awt.Panel;
import java.awt.TextField;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import java.util.Vector;
import java.util.Hashtable;
import java.util.Enumeration;
import java.util.StringTokenizer;

import java.io.File;
import java.io.IOException;

import java.security.Policy;
import com.ibm.aglets.security.PolicyDB;
import com.ibm.aglets.security.PolicyFileReader;
import com.ibm.aglets.security.PolicyFileWriter;
import com.ibm.aglets.security.PolicyGrant;
import com.ibm.aglets.security.PolicyPermission;
import com.ibm.aglets.security.PolicyFileParsingException;

import com.ibm.awb.misc.URIPattern;
import com.ibm.awb.misc.MalformedURIPatternException;
import com.ibm.awb.misc.Resource;

class GeneralPermissionEditor extends PermissionEditor {
	private static final String DEFAULT_LABEL_NAME = "Name";
	private static final int LENGTH_NAME = 15;

	private TextField name = new TextField(LENGTH_NAME);

	GeneralPermissionEditor() {
		this(DEFAULT_LABEL_NAME);
	}
	GeneralPermissionEditor(String labelName) {
		GridBagLayout grid = new GridBagLayout();

		setLayout(grid);

		GridBagConstraints cns = new GridBagConstraints();

		cns.weighty = 0.0;
		cns.fill = GridBagConstraints.HORIZONTAL;
		cns.ipadx = cns.ipady = 5;

		Label label = null;

		// name
		label = new Label(labelName);
		add(label);
		cns.weightx = 0.2;
		cns.gridwidth = GridBagConstraints.RELATIVE;
		grid.setConstraints(label, cns);

		add(name);
		cns.weightx = 1.0;
		cns.gridwidth = GridBagConstraints.REMAINDER;
		grid.setConstraints(name, cns);

		// actions
		label = new Label(LABEL_ACTIONS);
		add(label);
		cns.weightx = 0.2;
		cns.gridwidth = GridBagConstraints.RELATIVE;
		grid.setConstraints(label, cns);

		add(actions);
		cns.weightx = 1.0;
		cns.gridwidth = GridBagConstraints.REMAINDER;
		grid.setConstraints(actions, cns);
	}
	public String getText() {
		Vector args = new Vector();
		final String nam = name.getText();
		final String acts = actions.getText();
		final boolean n = nam != null &&!nam.equals("");
		final boolean a = acts != null &&!acts.equals("");

		if (n || a) {
			args.addElement(nam);
		} 
		if (a) {
			args.addElement(acts);
		} 
		return toText(args);
	}
	public void setText(String text) {
		parseText(text);
		final String nam = getArg(0);
		final String acts = getArg(1);

		if (nam != null) {
			name.setText(nam);
		} else {
			name.setText("");
		} 
		if (acts != null) {
			actions.setText(acts);
		} else {
			actions.setText("");
		} 
	}
}
